package com.douyin_spider.webmagic.Start.Impl;

import com.bj58.spat.wos.ClientConfig;
import com.bj58.spat.wos.WOSClient;
import com.bj58.spat.wos.request.UploadFileRequest;
import com.bj58.spat.wos.sign.Credentials;
import com.douyin_spider.webmagic.Pipeline.DouyinPipeline;
import com.douyin_spider.webmagic.Processor.DouyinProcessor;
import com.douyin_spider.webmagic.Start.Start;
import com.douyin_spider.webmagic.downloader.ImageDownloader;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.downloader.HttpClientDownloader;
import us.codecraft.webmagic.proxy.Proxy;
import us.codecraft.webmagic.proxy.SimpleProxyProvider;

import java.awt.*;
import java.io.File;
import java.io.IOException;

@Component
public class DouyinStart implements Start {

    @Autowired
    private DouyinProcessor douyinProcessor;

    @Autowired
    private DouyinPipeline douyinPipeline;
    @Override
    public void start() throws IOException {
        String url = "https://www.douyin.com/aweme/v1/web/emoji/list?msToken=Oes4nGHldwuYocrhOLlEgL4OvCdCpKBH2nJ7wjU7ipizL5QqxemuwPbx51TD4A76V761Z34S1wj4rwqTCGLCio5XuZd-RNdHkTyuqwpx7ggiuNOQPVknQIaWUKHaNhhPYlVoo-xmFLNwTIyuCVbg5uT3K_GQbg-tfTciwsKRdUW0vhYOnUaV3g%3D%3D";
//        HttpClientDownloader httpClientDownloader = new HttpClientDownloader();
        ImageDownloader imageDownloader = new ImageDownloader();
        imageDownloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("10.253.52.220",8888)));
        Spider.create(douyinProcessor)
                .addUrl(url)
                .setDownloader(imageDownloader)
                .addPipeline(douyinPipeline)
                .thread(1)
                .run();
        System.out.println("爬虫完成-------");
        System.out.println(douyinPipeline.list);
        new ObjectMapper().writeValue(new File("/Users/a58/backend/emoji_spider/emoji.json"), douyinPipeline.list);
    }
}
